package TestLeeTCode;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-05-11
 * Time: 23:20
 */
class Solution {
    public boolean backspaceCompare(String s, String t) {
        int cnt1 =0;
        int cnt2 =0;
        //计算两个字符串中的#号然后进行减去下标在两个指针进行比较
        for(int i=0;i<s.length();++i){
            if(s.charAt(i)=='#'){
                ++cnt1;
            }
        }
        for(int i=0;i<t.length();++i){
            if(t.charAt(i)=='#'){
                ++cnt2;
            }
        }
        int m = s.length()-2-cnt1*2;
        int n = t.length()-2-cnt2*2;
        if(m<0) m=0;
        if(n<0) n=0;
        if(m==0&&n==0){
            return true;
        }
        while(n>=0&&m>=0){
            if(s.charAt(m)!=t.charAt(n)){
                return false;
            }
            m--;
            n--;
        }
        return true;
    }
}
public class TestLeetCode {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.backspaceCompare("a#c","b");
    }
}
